var animated_cloud = false;
var animated_share = false;

var checkPagePosition = function () {
	t = $(document).scrollTop();
	if( t > top_height && !painted) {
		painted = true;
		if(jQuery.browser.mobile == true || is_min_width == true) {
			$("#m_top_bar").animate({
				backgroundColor: "#806DD8FF"
			}, 250);
			$("#m_drop_menu").animate({ backgroundColor: "#806DD8FF" }, 250);
		} else {
			$("#top_bar").animate({
				backgroundColor: "#806DD8FF"
			}, 250);
		}
	} else if(t < top_height && painted) {
		painted = false;
		if(jQuery.browser.mobile == true || is_min_width == true) {
			$("#m_top_bar").animate({
				backgroundColor: "transparent"
			}, 250);
			$("#m_drop_menu").animate({ backgroundColor: "transparent" }, 250);
		} else {
			$("#top_bar").animate({
				backgroundColor: "transparent"
			}, 250);
		}
	}
	var f_top = $("#features").position().top - 100;
	var e_top = $("#explore").position().top - 100;
	var c_top = $(document).height() - win_height - 100;
	if( t < f_top && i_pos != 0 ) {
		i_pos = 0;
		$("#m_indicator").animate({ left: 0, backgroundColor: "transparent" }, 250);
	} else if( t > f_top && t < e_top && i_pos != 1 ) {
		i_pos = 1;
		$("#m_indicator").animate({ left: 0, backgroundColor: "white" }, 250);
	} else if( t > e_top && t < c_top && i_pos != 2 ) {
		i_pos = 2;
		$("#m_indicator").animate({ left: 100, backgroundColor: "white" }, 250);
	} else if( t > c_top && i_pos != 3 ) {
		i_pos = 3;
		$("#m_indicator").animate({ left: 200, backgroundColor: "white" }, 250);
	}
	if(m_menu_visible) {
		hide_m_menu();
	}

	var ac_top = $("#cloud_page").position().top;
	if( t > ( ac_top - (win_height / 2) ) && animated_cloud == false) {
		$("#cloud_engine_img").css('margin-left', 100).css('opacity', 0).animate({ "margin-left" : 0, "opacity" : 1 }, 800);
		animated_cloud = true;
	}
	if( t < ( ac_top  - win_height ) && animated_cloud == true) {
		$("#cloud_engine_img").css('opacity', 0);
		animated_cloud = false;
	}
	var as_top = $("#share_page").position().top;
	if( t > ( as_top - (win_height / 2) ) && animated_share == false) {
		$("#share_phone_img").css('margin-left', -100).css('opacity', 0).animate({ "margin-left" : 0, "opacity" : 1 }, 800);
		animated_share = true;
	}
	if( t < ( as_top  - win_height ) && animated_share == true) {
		$("#share_phone_img").css('opacity', 0);
		animated_share = false;
	}
};

var painting = _.throttle(checkPagePosition, 300, {leading: false});
$(window).scroll(painting);
$(document).ready(function(){
    $('body').plusAnchor({
        easing: 'easeInOutExpo',
        speed:  600
    });
    // detect browser is mobile or not
	(function(a){(jQuery.browser=jQuery.browser||{}).mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|android|ipad|playbook|silk|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);
	if(jQuery.browser.mobile == true || is_min_width == true) {
		$("#top_bar").css('display', 'none');
	} else {
		$("#m_top_bar").css('display', 'none');
		$("#m_drop_menu").css('display', 'none');
		$("#top_video").css('display', 'block');
	}
});
$(window).resize( function() {
	is_min_width = $(window).width() < 640;
	win_height = $(window).height();
	top_height = $(window).height() * 0.2;
	painted = false;
	if(jQuery.browser.mobile == true || is_min_width == true) {
		$("#top_bar").css('display', 'none');
		$("#m_top_bar").css('display', 'block');
		$("#m_drop_menu").css('display', 'block');
		$("#top_video").css('display', 'none');
	} else {
		$("#top_bar").css('display', 'block');
		$("#m_top_bar").css('display', 'none');
		$("#m_drop_menu").css('display', 'none');
		$("#top_video").css('display', 'block');
	}
	painting();
});

document.createElement('video');document.createElement('audio');document.createElement('track');

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-56619970-1', 'auto');ga('send', 'pageview');

var m_menu_visible = false;
function show_m_menu() {
	m_menu_visible = true;
	if (painted) {
		$("#m_drop_menu").stop(true).animate({ backgroundColor: "#806DD8FF", top: 0 }, 250);
	} else {
		$("#m_drop_menu").stop(true).animate({ backgroundColor: "transparent", top: 0 }, 250);
	}
}
function hide_m_menu() {
	m_menu_visible= false;
	$("#m_drop_menu").stop(true).animate({ backgroundColor: "transparent", top: -100 }, 250);
}
var f_hovered = false;
var e_hovered = false;
var c_hovered = false;

$("#f_menu").hover( function() {
	$("#f_indicator").stop(true).css('top', 20).animate({ backgroundColor: "white", top: 34 }, 250);
}, function() {
	$("#f_indicator").stop(true).css('top', 34).animate({ backgroundColor: "transparent", top: 20 }, 250);
});
$("#e_menu").hover( function() {
	$("#e_indicator").stop(true).css('top', 20).animate({ backgroundColor: "white", top: 34 }, 250);
}, function() {
	$("#e_indicator").stop(true).css('top', 34).animate({ backgroundColor: "transparent", top: 20 }, 250);
});
$("#c_menu").hover( function() {
	$("#c_indicator").stop(true).css('top', 20).animate({ backgroundColor: "white", top: 34 }, 250);
}, function() {
	$("#c_indicator").stop(true).css('top', 34).animate({ backgroundColor: "transparent", top: 20 }, 250);
});
$("#m_menu_icon").click( function(){
	if(!m_menu_visible) {
		show_m_menu();
	} else {
		hide_m_menu();
	}
});

function arrow_down() {
	$("#top_arrow").css('margin-top', 0).animate({ marginTop: 10 }, 300, 'linear', function() { arrow_up(); });
}

function arrow_up() {
	$("#top_arrow").css('margin-top', 10).animate({ marginTop: 0 }, 300, 'linear', function() { arrow_down(); });
}

$(document).ready(function() {
	arrow_down();
});

var cur_video = 0;
var video_1 = videojs("#explore_video_1");
var video_2 = videojs("#explore_video_2");
var video_3 = videojs("#explore_video_3");
var video_4 = videojs("#explore_video_4");

video_1.on('play', function() {
	switch(cur_video) {
		case 2:
			video_2.pause();
			break;
		case 3:
			video_3.pause();
			break;
		case 4:
			video_4.pause();
			break;
	}
 	cur_video = 1;
});

video_2.on('play', function() {
	switch(cur_video) {
		case 1:
			video_1.pause();
			break;
		case 3:
			video_3.pause();
			break;
		case 4:
			video_4.pause();
			break;
	}
 	cur_video = 2;
});

video_3.on('play', function() {
	switch(cur_video) {
		case 1:
			video_1.pause();
			break;
		case 2:
			video_2.pause();
			break;
		case 4:
			video_4.pause();
			break;
	}
 	cur_video = 3;
});

video_4.on('play', function() {
	switch(cur_video) {
		case 2:
			video_2.pause();
			break;
		case 3:
			video_3.pause();
			break;
		case 1:
			video_1.pause();
			break;
	}
 	cur_video = 4;
});

